<?php
function _theme_pager($controller, $current_page, $total_items, $items_per_page = 12, $order = 'default', $paginate_limit = 1 ) {
    $output = '';
    $total_pages = ceil($total_items/$items_per_page);

    $output .= '<ul class="pager">' . "\n";

      if ($current_page > 1) {
        $output .= '<li class="previous-link">';
        $output .= anchor($controller . '/' . ($current_page-1) . '/' . $order, '&lt;&lt;');
        $output .- '</li>';
      }

      $dotshow = true;
      // walk through the list of pages
      for ( $i = 1; $i <= $total_pages; $i ++ ) {
         // If first or last page or the page number falls
         // within the pagination limit
         // generate the links for these pages
         if ($i == 1 || $i == $total_pages ||
               ($i >= $current_page - $paginate_limit &&
               $i <= $current_page + $paginate_limit) )
         {
            // reset the show dots flag
            $dotshow = true;
            // If it's the current page, leave out the link
            // otherwise set a URL field also
            if ($i != $current_page) {
                $output .= '<li class="pager-item pager">' . anchor($controller . '/' . $i . '/' . $order, $i) . '</li>' . "\n";
            }
            else {
              $output .= '<li class="pager-current pager">' . $i . '</li>' . "\n";
            }
         }
         // If ellipses dots are to be displayed
         // (page navigation skipped)
         else {
           if ($dotshow == true) {
               // set it to false, so that more than one
               // set of ellipses is not displayed
               $dotshow = false;
               $output .= '<li class="pager-delimiter pager">...</li>';
           }
         }
      }
    if ($current_page < $total_pages) {
      $output .= '<li class="next-link">';
      $output .= anchor($controller . '/' . ($current_page+1) . '/' . $order, '&gt;&gt;');
      $output .= '</li>';
    }
    $output .= '</ul>' . "\n";

    return $output;
}